/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: ServerMessage.java
 * Author: ckj
 * Date: 2024/7/21 下午10:12
 * Description:
 * 服务器个人发送消息
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package com.bosssoft.message;

import com.bosssoft.constants.MessageTypeConstant;
import com.bosssoft.utils.ReaderUtil;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ckj
 */
public class ServerMessage extends BaseMessage{
    public ServerMessage() {
        //null
    }

    @Override
    public BaseMessage parse(BufferedReader reader, Integer type) throws Exception {
        processContent(reader);
        return this;
    }
    private void processContent(BufferedReader reader) throws Exception {
        int contentLength = Integer.parseInt(ReaderUtil.readLineWithAes(reader));
        setContent(new ArrayList<>());
        for (int i = 0; i < contentLength; i++) {
            getContent().add(ReaderUtil.readLineWithAes(reader));
        }
        ReaderUtil.readLineWithAes(reader);
    }

    public ServerMessage build(List<String> content) {
        this.setType(MessageTypeConstant.SERVER_RESPONSE_MESSAGE);
        this.setHeader(new ArrayList<>());
        this.setContent(content);
        return this;
    }

    public static ServerMessage fileIsBeingReceived() {
        ArrayList<String> content = new ArrayList<>();
        content.add("服务器接收文件中");
        return new ServerMessage().build(content);
    }

    public static ServerMessage fileIsReceived() {
        ArrayList<String> content = new ArrayList<>();
        content.add("服务器接收文件完成");
        return new ServerMessage().build(content);
    }
}